package com.greendragon.service.backend.impl; 

import java.util.List;

import com.greendragon.persistence.dao.IArticalDao;
import com.greendragon.persistence.dao.ICommentDao;
import com.greendragon.persistence.domain.Artical;
import com.greendragon.persistence.domain.ArticalComment;
import com.greendragon.persistence.enmu.FetchOrderType;
import com.greendragon.persistence.enmu.LockType;
import com.greendragon.persistence.enmu.VerifyType;
import com.greendragon.service.backend.IArticalBackendService;


/** 
 * @author wulibin, exceptsky@gmail.com, 2011-10-27 上午08:20:22
 * 
 */
public class ArticalBackendService extends BaseBackendService<Artical> implements IArticalBackendService{
	private IArticalDao articalDao;
	private ICommentDao<ArticalComment> commentDao;
	
	@Override
	public void addComment(long aid, ArticalComment comment) {
		comment.setArtical(get(aid));
		commentDao.add(comment);
	}

	@Override
	public long getCommentCount(long aid) {
		return commentDao.getCountOfObj(aid, LockType.UNLOCK, VerifyType.VERIFY);
	}

	@Override
	public List<ArticalComment> getComments(long aid, int page) {
		return commentDao.getOfObj(aid, pageLength*page, pageLength, LockType.UNLOCK, VerifyType.VERIFY, FetchOrderType.CREATE_DESC);
	}
	
	public void setCommentDao(ICommentDao<ArticalComment> commentDao) {
		this.commentDao = commentDao;
	}

	public void setArticalDao(IArticalDao articalDao) {
		this.articalDao = articalDao;
		this.setDao(this.articalDao);
	}
}
 